$(function() {
    sch_api(1);
});

function sch_api(pagenum){
	$('.page_selector').html('');
	$('#list').html('');
	var datastr = '';
	var pagenum = parseInt(pagenum);
	if(pagenum)
	{
		datastr += '&page=' + pagenum;
	}
	if($('input[name="op"]').val() == 'auth'){
		datastr += '&status=3';
	}
	showCommonLayer("数据获取中……",3);
	$.ajax({
        type: "POST",
        url: "/admin/aj_publiclog.php",
        data: "action=index"+datastr,
        dataType: "json",
        success: function(json){
        	common_click();
        	var html = '';
            if(json.curtotal >0) {
            	$('.common_table').show();
            	$('.page_selector').show();
            	$('.PY_clew').hide();
            	$('.PY_clewcon').hide();

            	for(i=0; i<json.curtotal; i++)
				{
            		html += '<tr>';
					html += '<td>' + json.list[i]['id'] + '</td>';
					html += '<td>' + json.list[i]['service_line_no'] + '</td>';
					html += '<td>' + json.list[i]['index_name'] + '</td>';
					html += '<td>' + json.list[i]['db_flag'] + '</td>';
					html += '<td>' + json.list[i]['tb_name'] + '</td>';
					html += '<td>' + json.list[i]['status'] + '</td>';
					if($('input[name="op"]').val() == 'auth'){
						html += '<td><a href="publiclogdetail.php?id=' + json.list[i]['id'] + '">进入审核</a></td>';
					} else {
						if(json.list[i]['config_status'] == 3 || json.list[i]['config_status'] == 4){
							html += '<td><a href="javascript:;" onclick="withdraw(' + json.list[i]['service_line_no'] + ');">撤销审核申请</a>';
							html += '&nbsp;&nbsp;&nbsp;<a href="publiclogdetail.php?id=' + json.list[i]['newid'] + '&op=plain">查看</a></td>';
						}else{
							html += '<td><a href="publiclogedit.php?id=' + json.list[i]['id'] + '">修改</a></td>';
						}
					}
					html += '</tr>';
				}
				$('.page_selector').html(json.pagehtml);

				$('.btn_num').click(function(){
					sch_api($(this).attr('rel'));
				});
				$('#list').html(html);
				$('body').trigger('click');
            } else {
            	$('.page_selector').html('');
            	$('.common_table').hide();
            	$('.page_selector').hide();
            	$('.PY_clew').show();
            	$('.PY_clewcon').show();
            }
        }
    }); 
}

function withdraw(srvno){
	var srvno = parseInt(srvno);
	var datastr = '';
	datastr += '&srvno=' + srvno;
	$.ajax({
        type: "POST",
        url: "/admin/aj_publiclog.php",
        data: "action=withdraw"+datastr,
        dataType: "json",
        success: function(json){
        	if(json.status){
        		showCommonLayer(json.msg, 4);
        		location.href = 'public_log.php';
        		return;
        	} else {
        		showCommonLayer(json.msg, 4);
        		return false;
        	}
        }
    }); 
}